<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="所属上级标准" :labelCol="labelCol" :wrapperCol="wrapperCol"-->
<!--                               prop="achievementStandardId">-->
<!--              <j-dict-select-tag type="list" v-model="model.achievementStandardId"-->
<!--                                 dictCode="ach_achievement_standard,achievement_standard_name,id"-->
<!--                                 placeholder="请输入所属上级标准" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="标准分项编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemCode">-->
          <!--              <a-input v-model="model.standItemCode" placeholder="请输入标准分项编码"></a-input>-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="试卷名称" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="standItemName">
              <a-input v-model="model.standItemName" placeholder="请输入试卷名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="权重系数" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="standItemName">
              <a-input v-model="model.standItemWeightCoefficient" placeholder="请输入权重系数"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="简称" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="standItemAliasname">
              <a-input v-model="model.standItemAliasname" placeholder="请输入简称"></a-input>
            </a-form-model-item>
          </a-col>
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="分数最低分(含)" :labelCol="labelCol" :wrapperCol="wrapperCol"-->
          <!--                               prop="standItemLowestScore">-->
          <!--              <a-input-number v-model="model.standItemLowestScore" placeholder="请输入分数最低分(含)" style="width: 100%" />-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="分数最高分(不含)" :labelCol="labelCol" :wrapperCol="wrapperCol"-->
          <!--                               prop="standItemHighestScore">-->
          <!--              <a-input-number v-model="model.standItemHighestScore" placeholder="请输入分数最高分(不含)" style="width: 100%" />-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col :span="24">
            <!--            特殊限制-->
            <a-form-model-item label="特殊限制" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="standItSpecialRestrictions">
              <a-input-number v-model="model.standItSpecialRestrictions" placeholder="请输入特殊限制"
                              style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="顺序序号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemOrder">
              <a-input-number v-model="model.standItemOrder" placeholder="请输入顺序序号" style="width: 100%" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="上级项目id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemFatherId">-->
          <!--              <a-input v-model="model.standItemFatherId" placeholder="请输入上级项目id"></a-input>-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="是否启用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="izOpen">
              <j-dict-select-tag type="list" v-model="model.izOpen"
                                 dictCode="iz_open" placeholder="请选择是否启用" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'AchAchieveStandardItemForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/achachievestandarditem/achAchieveStandardItem/add',
        edit: '/achachievestandarditem/achAchieveStandardItem/edit',
        queryById: '/achachievestandarditem/achAchieveStandardItem/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        }

      })
    }
  }
}
</script>